package com.pbl6.back.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Arrays;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pbl6.back.service.IArrangeService;
import com.pbl6.back.mapper.ArrangeMapper;
import com.pbl6.back.domain.Arrange;
import xin.altitude.cms.common.entity.AjaxResult;
import java.util.List;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import xin.altitude.cms.common.entity.PageEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@RestController
@RequestMapping("/back/arrange")
public class ArrangeController{
    @Autowired
    private IArrangeService arrangeService;
    @GetMapping("/page")
    public AjaxResult page(PageEntity pageEntity,Arrange arrange){
        return AjaxResult.success(arrangeService.page(pageEntity.toPage(), Wrappers.lambdaQuery(arrange)));
    }
    @GetMapping("/list")
    public AjaxResult list(Arrange arrange){
        LambdaQueryWrapper<Arrange> arrangeLambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (arrange.getOperator() !=null&& !" ".equals(arrange.getOperator())) {
            arrangeLambdaQueryWrapper.like(Arrange::getOperator,arrange.getOperator());
        }
        if (arrange.getRubric() !=null&& !" ".equals(arrange.getRubric())) {
        arrangeLambdaQueryWrapper.like(Arrange::getRubric,arrange.getRubric());
        }
        if (arrange.getTask() !=null&& !" ".equals(arrange.getTask())) {
            arrangeLambdaQueryWrapper.like(Arrange::getTask, arrange.getTask());
        }
        return AjaxResult.success(arrangeService.list(arrangeLambdaQueryWrapper));
        /*
        LambdaQueryWrapper<Arrange> arr= Wrappers.lambdaQuery(arrange);
        return AjaxResult.success(arrangeService.list(arr));*/
    }
    @PostMapping("/push")
    public AjaxResult add(@RequestBody Arrange arrange) {
        return AjaxResult.success(arrangeService.save(arrange));
    }
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody Arrange arrange) {
        return AjaxResult.success(arrangeService.updateById(arrange));
    }
    @DeleteMapping("/delete/{ids}")
    public AjaxResult delete(@PathVariable Integer[] ids) {
        return AjaxResult.success(arrangeService.removeByIds(Arrays.asList(ids)));
    }
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Integer id) {
        return AjaxResult.success(arrangeService.getById(id));
    }
}
